
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class demo2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        String[] ss = s.split("-");
        String[] p = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "joker", "JOKER"};
        List<String> lst = Arrays.asList(p);
        if (ss[0].equals("joker JOKER") || ss[1].equals("joker JOKER")) {
            System.out.println("joker JOKER");
        } else {
            String[] s1 = ss[0].split(" ");
            String[] s2 = ss[1].split(" ");
            int len1 = s1.length;
            int len2 = s2.length;
            if (len1 == len2) {
                String ch1 = s1[0];
                String ch2 = s2[0];
                int num1 = lst.indexOf(ch1);
                int num2 = lst.indexOf(ch2);
                if (num1 > num2) {
                    System.out.println(ss[0]);
                } else {
                    System.out.println(ss[1]);
                }
            } else {
                if(len1 == 4 ){
                    System.out.println(ss[0]);
                }else if(len2 == 4){
                    System.out.println(ss[1]);
                }else{
                    System.out.println("ERROR");
                }
            }
        }
    }
}